<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 父组件拿子组件(对象)的属性 $children $refs -->

    <div id="hello">
        <!-- 这里使用了多少个cpn 就代表父组件里有多少个子组件 -->
        <cpn></cpn>
        <cpn></cpn>
        <cpn></cpn>
        <button @click='btnclick'>showChlidrens</button>
    </div>
    <template id="temp1">
        <div>
            <h6>我是子组件</h6>
        </div>
    </template>
    <script src="../../vue.js"></script>
    <script>
        const vue01 = new Vue({
            el: '#hello',
            
            methods: {
                btnclick() {
                    // 拿到子组件对象数组 
                    console.log(this.$children)
                    //拿到第一个子组件的方法和属性
                    this.$children[0].showmessage();
                    console.log(this.$children[0].age);
                    
                }
            },

            components: {
                cpn :{
                    template:'#temp1',
                    methods: {
                        showmessage(){
                            console.log('子组件方法')
                        }
                    },
                    data() {
                        return {
                            name:'cpn\'s name',
                            age:22,
                        }
                    },
                }
            },
        })
    </script>
</body>

</html>